/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class Tdp_precioDAOImpl implements orm.dao.Tdp_precioDAO {
	public Tdp_precio loadTdp_precioByORMID(int pre_id) throws PersistentException {
		try {
			PersistentSession session = orm.PruebaPDS1PersistentManager.instance().getSession();
			return loadTdp_precioByORMID(session, pre_id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tdp_precio getTdp_precioByORMID(int pre_id) throws PersistentException {
		try {
			PersistentSession session = orm.PruebaPDS1PersistentManager.instance().getSession();
			return getTdp_precioByORMID(session, pre_id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tdp_precio loadTdp_precioByORMID(int pre_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PruebaPDS1PersistentManager.instance().getSession();
			return loadTdp_precioByORMID(session, pre_id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tdp_precio getTdp_precioByORMID(int pre_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PruebaPDS1PersistentManager.instance().getSession();
			return getTdp_precioByORMID(session, pre_id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tdp_precio loadTdp_precioByORMID(PersistentSession session, int pre_id) throws PersistentException {
		try {
			return (Tdp_precio) session.load(orm.Tdp_precio.class, new Integer(pre_id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tdp_precio getTdp_precioByORMID(PersistentSession session, int pre_id) throws PersistentException {
		try {
			return (Tdp_precio) session.get(orm.Tdp_precio.class, new Integer(pre_id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tdp_precio loadTdp_precioByORMID(PersistentSession session, int pre_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tdp_precio) session.load(orm.Tdp_precio.class, new Integer(pre_id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tdp_precio getTdp_precioByORMID(PersistentSession session, int pre_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tdp_precio) session.get(orm.Tdp_precio.class, new Integer(pre_id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tdp_precio[] listTdp_precioByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.PruebaPDS1PersistentManager.instance().getSession();
			return listTdp_precioByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tdp_precio[] listTdp_precioByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PruebaPDS1PersistentManager.instance().getSession();
			return listTdp_precioByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tdp_precio[] listTdp_precioByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tdp_precio as Tdp_precio");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Tdp_precio[]) list.toArray(new Tdp_precio[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tdp_precio[] listTdp_precioByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tdp_precio as Tdp_precio");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Tdp_precio[]) list.toArray(new Tdp_precio[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tdp_precio loadTdp_precioByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.PruebaPDS1PersistentManager.instance().getSession();
			return loadTdp_precioByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tdp_precio loadTdp_precioByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PruebaPDS1PersistentManager.instance().getSession();
			return loadTdp_precioByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tdp_precio loadTdp_precioByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Tdp_precio[] tdp_precios = listTdp_precioByQuery(session, condition, orderBy);
		if (tdp_precios != null && tdp_precios.length > 0)
			return tdp_precios[0];
		else
			return null;
	}
	
	public Tdp_precio loadTdp_precioByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Tdp_precio[] tdp_precios = listTdp_precioByQuery(session, condition, orderBy, lockMode);
		if (tdp_precios != null && tdp_precios.length > 0)
			return tdp_precios[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTdp_precioByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.PruebaPDS1PersistentManager.instance().getSession();
			return iterateTdp_precioByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTdp_precioByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PruebaPDS1PersistentManager.instance().getSession();
			return iterateTdp_precioByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTdp_precioByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tdp_precio as Tdp_precio");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTdp_precioByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tdp_precio as Tdp_precio");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tdp_precio createTdp_precio() {
		return new orm.Tdp_precio();
	}
	
	public boolean save(orm.Tdp_precio tdp_precio) throws PersistentException {
		try {
			orm.PruebaPDS1PersistentManager.instance().saveObject(tdp_precio);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Tdp_precio tdp_precio) throws PersistentException {
		try {
			orm.PruebaPDS1PersistentManager.instance().deleteObject(tdp_precio);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tdp_precio tdp_precio)throws PersistentException {
		try {
			orm.Tda_tipoGasolina[] lTda_tipoGasolinas = tdp_precio.tda_tipoGasolina.toArray();
			for(int i = 0; i < lTda_tipoGasolinas.length; i++) {
				lTda_tipoGasolinas[i].setTdp_preciopre(null);
			}
			return delete(tdp_precio);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tdp_precio tdp_precio, org.orm.PersistentSession session)throws PersistentException {
		try {
			orm.Tda_tipoGasolina[] lTda_tipoGasolinas = tdp_precio.tda_tipoGasolina.toArray();
			for(int i = 0; i < lTda_tipoGasolinas.length; i++) {
				lTda_tipoGasolinas[i].setTdp_preciopre(null);
			}
			try {
				session.delete(tdp_precio);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Tdp_precio tdp_precio) throws PersistentException {
		try {
			orm.PruebaPDS1PersistentManager.instance().getSession().refresh(tdp_precio);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Tdp_precio tdp_precio) throws PersistentException {
		try {
			orm.PruebaPDS1PersistentManager.instance().getSession().evict(tdp_precio);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tdp_precio loadTdp_precioByCriteria(Tdp_precioCriteria tdp_precioCriteria) {
		Tdp_precio[] tdp_precios = listTdp_precioByCriteria(tdp_precioCriteria);
		if(tdp_precios == null || tdp_precios.length == 0) {
			return null;
		}
		return tdp_precios[0];
	}
	
	public Tdp_precio[] listTdp_precioByCriteria(Tdp_precioCriteria tdp_precioCriteria) {
		return tdp_precioCriteria.listTdp_precio();
	}
}
